Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly resolve tags for function overloads #30253

Merged
merged 6 commits into from
Jan 10, 2020

Conversation

jeanp413
Copy link
Contributor

@jeanp413 jeanp413 commented Mar 7, 2019

Fixes #30181 #35933

@DanielRosenwasser
Copy link
Member

There's a common thing people do where they only add JSDoc to the first overload. My feeling is that we should first try to get JSDoc for the applicable overload, and if we don't find anything, we should try to find JSDoc for any other overload. Thoughts @mjbvz @RyanCavanaugh?

@ajafff
Copy link
Contributor

ajafff commented Mar 7, 2019

I typically don't add jsdoc comments, but when I do, I use it to deprecate a single overload.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Mar 7, 2019

@ajafff please post future comments in the form of a captioned image meme if possible.

image

@sandersn
Copy link
Member

sandersn commented Jul 3, 2019

@DanielRosenwasser That's a good point. I'm going to look at Definitely Typed.

So far, it looks like the numbers are really low compared to compared to the total number of overloads. Admittedly, I'm only looking at d.ts and DT is relatively well-documented.

Some super early numbers:
Two-overload sets: 50 of 1,000,000 only document the first overload.
Three-overload sets: 25 of 5000.

I'll run over all of DT (and its dependencies) but right now I think this is a good change.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion, plus a request for more tests.

@@ -501,7 +501,7 @@ namespace ts.SymbolDisplay {

if (!documentation) {
documentation = symbol.getDocumentationComment(typeChecker);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should add the same code here.

/////**
//// * @tag Tag text
//// */
////declare function /*2*/foo(x: number): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is a good start.

  1. can you add tests for documentation as well?
  2. can you add a test with the sequences [doc/no-tag, doc/tag], [doc/no-tag, doc/no-tag], [no-doc/no-tag, doc/tag], [no-doc/no-tag, doc/no-tag], [no-doc/no-tag, no-doc/tag]? There are other combinations but those are the ones that come to mind.
  3. I couldn't get this to work in my editor when I played with it locally, although the tests pass. Probably I just set it up wrong, but you might want to make sure it at leasts works in your editor.

@sandersn
Copy link
Member

sandersn commented Jul 3, 2019

Actually, looks like I was asking the wrong question. Turns out the number of first-jsdoc-only overloads is quite high, of the overloads with jsdoc:
Selection_045

The yellow line is overloads with any jsdoc; the red line is overloads with jsdoc only on the first signature. Blue is all overloads. X=size of overload set; Y=number of each size of set.

Looks like @DanielRosenwasser is right; the jsdoc for the first signature of the overload should be applied to all others that do not themselves have jsdoc. The same is not true for non-first signatures.

@jeanp413
Copy link
Contributor Author

@sandersn Pushed a better fix and added more unit tests

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good. The tests are subtly wrong in a couple of places. Can you investigate? If you no longer have time, let me know and I'll take a look.

{ name: "f3", text: "function f3(a: number): number (+1 overload)" },
{ name: "f4", text: "function f4(a: number): number (+1 overload)", documentation: "this is signature 4 - with number parameter" },
],
},
{
marker: "18",
includes: [
{ name: "i1_i", text: "var i1_i: i1\nnew (b: number) => any (+1 overload)" },
{ name: "i1_i", text: "var i1_i: i1\nnew (b: number) => any (+1 overload)", documentation: "new 1" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this documentation is supposed to be on new (a: string), not new (b: number).

Copy link
Contributor Author

@jeanp413 jeanp413 Jan 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look at this and it's working as intended following:

the jsdoc for the first signature of the overload should be applied to all others that do not themselves have jsdoc

Is this an exception to the above rule?
Should this exception only be applied when useConstructSignatures === true?

if (useConstructSignatures) {
displayParts.push(keywordPart(SyntaxKind.NewKeyword));
displayParts.push(spacePart());
}
addSignatureDisplayParts(signature, allSignatures, TypeFormatFlags.WriteArrowStyleSignature);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I just missed that rule.

@@ -363,7 +363,7 @@ verify.signatureHelp({ marker: "38", overloadsCount: 2, docComment: "this is sig
verify.quickInfoAt("38q", "var i3_i: i3\n(a: number) => number (+1 overload)", "this is signature 1");

verify.signatureHelp({ marker: "39", overloadsCount: 2 });
verify.quickInfoAt("39q", "var i3_i: i3\n(b: string) => number (+1 overload)");
verify.quickInfoAt("39q", "var i3_i: i3\n(b: string) => number (+1 overload)", "this is signature 1");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same: this documentation is supposed to be on (a: number) not (b: string).

@@ -428,7 +428,7 @@ verify.signatureHelp({ marker: "57", overloadsCount: 2, docComment: "c2 1" });
verify.quickInfoAt("57q", "constructor c2(a: number): c2 (+1 overload)", "c2 1");

verify.signatureHelp({ marker: "58", overloadsCount: 2 });
verify.quickInfoAt("58q", "constructor c2(b: string): c2 (+1 overload)");
verify.quickInfoAt("58q", "constructor c2(b: string): c2 (+1 overload)", "c2 1");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same: (a: number) is the one with jsdoc, not (b: string)

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion, I didn't re-read the whole thread in enough detail.

@sandersn sandersn merged commit 79dcd3d into microsoft:master Jan 10, 2020
@jeanp413 jeanp413 deleted the fix-quick-info-wrong-tag branch January 10, 2020 21:29
Kingwl pushed a commit to Kingwl/TypeScript that referenced this pull request Mar 4, 2020
* Correctly resolve tags for function overloads. Fixes microsoft#30181

* Better fix for microsoft#30181. Added more unit tests

* Fix commentsOverloads tests

* Fallback to first signature when doc and tags are empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quick info returns wrong jsdoc tag for function overload
4 participants